import Vue from 'vue'
import VueRouter from 'vue-router'
import {
	getLocalStorage
} from "../utils/storage";
Vue.use(VueRouter)

const routes = [{
	path: '/',
	name: 'Login',
	component: resolve => require(['@/views/Login.vue'], resolve),
	meta: {
		requireAuth: false
	}
},
{
	path: '/test',
	name: 'Test',
	component: resolve => require(['@/views/Test.vue'], resolve),
	meta: {
		requireAuth: false
	}
},
{
	path: '/SmartPidPage',
	name: 'SmartPidPage',
	component: resolve => require(['@/views/SmartPid/HomePage.vue'], resolve),
	meta: {
		requireAuth: false
	},
	children: [{
		path: '/SmartPidPage/Content',
		name: 'SmartPidPageContent',
		component: resolve => require(['@/views/SmartPid/Content.vue'], resolve),
		meta: {
			requireAuth: false
		},
		children: [{
			path: '/pidSvgTabView',
			name: 'pidSvgTabView',
			component: resolve => require(['../components/SmartPid/pidSvgTabView.vue'], resolve),
			meta: {
				requireAuth: false
			},
		}, {
			path: '/pidDocumentView',
			name: 'pidDocumentView',
			component: resolve => require(['../components/SmartPid/pidDocumentView.vue'], resolve),
			meta: {
				requireAuth: false
			},
		}]
	}]

},

{
	path: '/LineContent',
	name: 'LineContent',
	component: resolve => require(['@/components/TabelLineCadViews/BSDetailConmpontents/LineContent.vue'], resolve),
	meta: {
		requireAuth: false
	}
},
{
	path: '/HomePage',
	name: 'HomePage',
	component: resolve => require(['@/views/HomePage.vue'], resolve),
	children: [{
		path: '/HomePage/Content',
		name: 'Content',
		component: resolve => require(['@/views/Content.vue'], resolve),
		meta: {
			requireAuth: true
		},
		children: [{
			path: '/HomePageView',
			name: 'HomePageView',
			component: resolve => require(['../components/ContentView/HomePageView.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/DeviceLogin',
			name: 'DeviceLogin',
			component: resolve => require(['../components/DeviceLogin/index.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/UserPageView',
			name: 'UserPageView',
			component: resolve => require(['../components/ContentView/UserPageView.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/PrivilegeManagement',
			name: 'PrivilegeManagement',
			component: resolve => require(['../components/ContentView/PrivilegeManagement.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/FunctionPageView',
			name: 'FunctionPageView',
			component: resolve => require(['../components/ContentView/FunctionPageView.vue'], resolve),
			// component: resolve => require(['../views/TestPicPage.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/SySView',
			name: 'SySView',
			component: resolve => require(['@/views/SySView.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/CustomerAView',
			name: 'CustomerAView',
			component: resolve => require(['@/components/Customize/Customer003/views/CustomerAView/CustomerAView.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/PipingManagement',
			name: 'PipingManagement',
			component: resolve => require(['@/components/Customize/Customer003/views/PipingManagement/PipingManagement.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/EvaluationView',
			name: 'EvaluationView',
			component: resolve => require(['@/views/EvaluationView.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/BHView',
			name: 'BHView',
			component: resolve => require(['@/views/BHView.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/PlanView',
			name: 'PlanView',
			component: resolve => require(['@/views/PlanView.vue'], resolve),
			meta: {
				requireAuth: true
			},
		},
		{
			path: '/Setting',
			name: 'Setting',
			component: resolve => require(['@/components/EnvironmentSetting/Content.vue'], resolve),
			meta: {
				requireAuth: true
			},
			children: [{
				path: '/EnvironmentTbs',
				name: 'EnvironmentTbs',
				component: resolve => require(['@/components/EnvironmentSetting/Tabs/EnvironmentTbs.vue'], resolve),
				meta: {
					requireAuth: true
				},
			},
			{
				path: '/Term',
				name: 'Term',
				component: resolve => require(['@/components/EnvironmentSetting/Tabs/Term.vue'], resolve),
				meta: {
					requireAuth: true
				},
			},
			{
				path: '/Editer',
				name: 'Editer',
				component: resolve => require(['@/components/EnvironmentSetting/Tabs/Editer/Editer.vue'], resolve),
				meta: {
					requireAuth: true
				},
			},
			{
				path: '/Unit',
				name: 'Unit',
				component: resolve => require(['@/components/EnvironmentSetting/Tabs/Unit/Unit.vue'], resolve),
				meta: {
					requireAuth: true
				},
			},
			{
				path: '/Ledger',
				name: 'Ledger',
				component: resolve => require(['@/components/EnvironmentSetting/Tabs/Ledger/index.vue'], resolve),
				meta: {
					requireAuth: true
				},
			},
			{
				path: '/Temperature',
				name: 'Temperature',
				component: resolve => require(['@/components/EnvironmentSetting/Tabs/Temperature/index.vue'], resolve),
				meta: {
					requireAuth: true
				},
			},
			{
				path: '/Calc',
				name: 'Calc',
				component: resolve => require(['@/components/EnvironmentSetting/Tabs/Calc/index.vue'], resolve),
				meta: {
					requireAuth: true
				},
			},
			{
				path: '/MAT',
				name: 'MAT',
				component: resolve => require(['@/components/EnvironmentSetting/Tabs/MAT/index.vue'], resolve),
				meta: {
					requireAuth: true
				},
			},
			]
		},
		{
			path: '/ExcelView',
			name: 'ExcelView',
			component: resolve => require(['@/components/ContentView/ExcelContent.vue'], resolve),
			meta: {
				requireAuth: true
			},
			children: [{
				path: '/ExcelExport',
				name: 'ExcelExport',
				component: resolve => require(['@/components/Excel/Export.vue'], resolve),
				meta: {
					requireAuth: true
				},
			}]
		},
		{
			path: '/ReportFormView',
			name: 'ReportFormView',
			component: resolve => require(['@/components/ContentView/ReportForm.vue'], resolve),
			meta: {
				requireAuth: true
			},
			children: [{
				path: '/ReportFormTable',
				name: 'ReportFormTable',
				component: resolve => require(['@/components/ReportForm/ReportFormTable.vue'], resolve),
				meta: {
					requireAuth: true
				},
			}]
		}
		]
	}]
},
{
	path: '/CAD',
	name: 'CAD',
	component: resolve => require(['@/views/CadView.vue'], resolve),
	meta: {
		requireAuth: true
	},
},
{
	path: '/CAD1',
	name: 'CAD1',
	component: resolve => require(['@/views/CadViewNew.vue'], resolve),
	meta: {
		requireAuth: true
	},
},
{
	path: '/PlanAutoSet',
	name: 'PlanAutoSet',
	component: resolve => require(['@/components/Plan/PlanAutoSet.vue'], resolve),
	meta: {
		requireAuth: true
	},
},
{
	path: '/pfdCAD',
	name: 'pfdCAD',
	component: resolve => require(['@/views/pfdCadView.vue'], resolve),
	meta: {
		requireAuth: true
	},
},
{
	path: '/editRelation',
	name: 'editRelation',
	// component: resolve => require(['@/components/ThreeDScene/threeDBaseCom.vue'], resolve),
	// component: resolve => require(['@/components/ThreeDScene/ThreeDScene.vue'], resolve),
	component: resolve => require(['@/views/EditRelationPage.vue'], resolve),
	meta: {
		requireAuth: true
	},
},
{
	path: '/test3DMarker',
	name: 'test3DMarker',
	// component: resolve => require(['@/components/ThreeDScene/threeDBaseCom.vue'], resolve),
	// component: resolve => require(['@/components/ThreeDScene/ThreeDScene.vue'], resolve),
	component: resolve => require(['@/views/test3DMarkerPage.vue'], resolve),
	meta: {
		requireAuth: true
	},
},
{
	path: '/SCENE',
	name: 'SCENE',
	component: resolve => require(['@/views/Scene.vue'], resolve),
	meta: {
		requireAuth: true
	},
},
{
	path: '/PicView',
	name: 'PicView',
	component: resolve => require(['@/views/PicView.vue'], resolve),
	meta: {
		requireAuth: true
	},
},

]

const router = new VueRouter({
	mode: 'hash',
	base: process.env.BASE_URL,
	routes
})

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

router.beforeEach((to, from, next) => {
	console.log(to);
	if (!to.meta.requireAuth) {
		next();
		return;
	}

	if (!sessionStorage.token) {
		if (to.path !== "/")
			return next({
				path: '/',
				query: {
					redirect: to.fullPath
				} // 将跳转的路由path作为参数，登录成功后跳转到该路由
			})
	}

	if (!getLocalStorage('token')) {
		if (to.path !== "/")
			return next({
				path: '/',
				query: {
					redirect: to.fullPath
				} // 将跳转的路由path作为参数，登录成功后跳转到该路由
			})
	}
	next();

})

export default router